package com.msmall.community.job;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.msmall.base.cache.CacheFactory;
import com.msmall.base.util.Constants;
import com.msmall.community.vote.model.VoteModule;
import com.msmall.community.vote.service.VoteManager;

public class VoteJob {
	private static final Log log = LogFactory.getLog(VoteJob.class);
	
	private VoteManager voteManager;
	
	public void refreshTravelVote(){
		List votes = voteManager.loadTravelVote();
		List<VoteModule> vms = new ArrayList<VoteModule>();
		if(votes == null || votes.size() == 0){
			log.debug("NO vote Travel found");
			return ;
		}
		for(int i=0; i<votes.size(); i++){
			Object[] obj = (Object[]) votes.get(i);
			Long voted = (Long) obj[0];
			Integer count = Integer.valueOf(String.valueOf(obj[1]));
			String avatar = (String) obj[2];
			VoteModule m = new VoteModule(voted, count, avatar);
			vms.add(m);
		}
		CacheFactory.getInstance().getCache(Constants.CACHE_NAME_COMMON).put(Constants.CACHE_KEY_VOTE_TRAVEL_LIST, vms);
	}

	public void setVoteManager(VoteManager voteManager) {
		this.voteManager = voteManager;
	}
}
